package clientGUI.user.ISD;

import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JComboBox;
import java.awt.Insets;
import java.awt.FlowLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JOptionPane;

import java.awt.BorderLayout;
import java.util.ArrayList;

import javax.swing.JButton;

import college.general;

import clientGUI.CollegeClientGUI;
import clientGUI.user.Controllers.ISD.ChooseCommisionController;
import clientGUI.userPanels.UPanel;
import clientserver.Client;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ISDChooseCommision extends UPanel {
	private JComboBox firstmCB;
	private JComboBox secondmCB;
	private ChooseCommisionController controller;
	private JComboBox chairmanCB;

	public ISDChooseCommision(Client cl) {
		super();
		controller= new ChooseCommisionController(cl);
		
		ArrayList<String> all_ise=controller.getCandidates();
		System.out.println("all-ise="+all_ise.toString());
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JLabel lblEngeneerId = new JLabel("First Committee Member:");
		GridBagConstraints gbc_lblEngeneerId = new GridBagConstraints();
		gbc_lblEngeneerId.insets = new Insets(0, 0, 5, 5);
		gbc_lblEngeneerId.anchor = GridBagConstraints.EAST;
		gbc_lblEngeneerId.gridx = 1;
		gbc_lblEngeneerId.gridy = 2;
		add(lblEngeneerId, gbc_lblEngeneerId);
		
		firstmCB = new JComboBox(all_ise.toArray());
		GridBagConstraints gbc_firstmCB = new GridBagConstraints();
		gbc_firstmCB.insets = new Insets(0, 0, 5, 0);
		gbc_firstmCB.anchor = GridBagConstraints.WEST;
		gbc_firstmCB.gridx = 2;
		gbc_firstmCB.gridy = 2;
		firstmCB.setSelectedItem(controller.getfirstMember());
		add(firstmCB, gbc_firstmCB);
		
		JLabel lblCommisionPost = new JLabel("Second Committee Member:");
		GridBagConstraints gbc_lblCommisionPost = new GridBagConstraints();
		gbc_lblCommisionPost.anchor = GridBagConstraints.EAST;
		gbc_lblCommisionPost.insets = new Insets(0, 0, 5, 5);
		gbc_lblCommisionPost.gridx = 1;
		gbc_lblCommisionPost.gridy = 3;
		add(lblCommisionPost, gbc_lblCommisionPost);
		
		secondmCB = new JComboBox(all_ise.toArray());
		GridBagConstraints gbc_secondmCB = new GridBagConstraints();
		gbc_secondmCB.insets = new Insets(0, 0, 5, 0);
		gbc_secondmCB.anchor = GridBagConstraints.WEST;
		gbc_secondmCB.gridx = 2;
		gbc_secondmCB.gridy = 3;
		secondmCB.setSelectedItem(controller.getsecondMember());
		add(secondmCB, gbc_secondmCB);
setName("Committee"); 
JLabel lblCommisionChairman = new JLabel("Committee Chairman:");
GridBagConstraints gbc_lblCommisionChairman = new GridBagConstraints();
gbc_lblCommisionChairman.anchor = GridBagConstraints.EAST;
gbc_lblCommisionChairman.insets = new Insets(0, 0, 5, 5);
gbc_lblCommisionChairman.gridx = 1;
gbc_lblCommisionChairman.gridy = 4;
add(lblCommisionChairman, gbc_lblCommisionChairman);

chairmanCB = new JComboBox(all_ise.toArray());
GridBagConstraints gbc_chairmanCB = new GridBagConstraints();
gbc_chairmanCB.anchor = GridBagConstraints.WEST;
gbc_chairmanCB.insets = new Insets(0, 0, 5, 0);
gbc_chairmanCB.gridx = 2;
gbc_chairmanCB.gridy = 4;
chairmanCB.setSelectedItem(controller.getchairman());
add(chairmanCB, gbc_chairmanCB);

JButton btnSet = new JButton("Set");
btnSet.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent arg0) {
		
		String f=(String) firstmCB.getSelectedItem();
		String s=(String) secondmCB.getSelectedItem();
		String c=(String) chairmanCB.getSelectedItem();
		
		if(controller.choosecommision(f, s, c))   controller.savecommision();
		else
			general.alert("You can't choose same user for more than one position in  Committee. Ty again pls");
	}
});
GridBagConstraints gbc_btnSet = new GridBagConstraints();
gbc_btnSet.insets = new Insets(0, 0, 5, 5);
gbc_btnSet.gridx = 1;
gbc_btnSet.gridy = 5;
add(btnSet, gbc_btnSet);
	}

}
